﻿using Common.Attributes;
using QGZX.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Script.Serialization;


namespace QGZX.Logic.Admin
{
    public class FinanceController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetDatas()
        {
            //string CompanyId = Request.QueryString["CompanyId"];
            
            string year = "2014";
            IEnumerable<IGrouping<string,MODEL.qgzx_salary>> qgzx_salary = OperateContext.Current.BLLSession.Iqgzx_salaryBLL.GetListBy
                (x => x.IsGrantSuccess == 1,s => s.WorkStudentNum).Where(x =>x.DistriTime.ToString().Contains(year)).GroupBy(x => x.WorkStudentNum);
            IList<IGrouping<string, MODEL.qgzx_salary>> salaryList = qgzx_salary.ToList();
            
            List<MODEL.test> students = new List<MODEL.test>();
            foreach(IGrouping<string,MODEL.qgzx_salary> salary in salaryList)
            {
                MODEL.test student = new MODEL.test();
                student.name = salary.FirstOrDefault().WorkStudentName;
                student.num = salary.FirstOrDefault().WorkStudentNum;
                student.positions = salary.Count();
                student.wages = salary.Sum(x => x.SumOfMoney);
                students.Add(student);
            }

            int pageSize = int.Parse(Request.Form["rows"]);
            int pageIndex = int.Parse(Request.Form["page"]);
            List<MODEL.test> lists = students.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            int rowCount = lists.Count();

            MODEL.EasyUIModel.DataGridModel dgMode = new MODEL.EasyUIModel.DataGridModel()
            {
                total = rowCount,
                rows = lists,
                footer = null,
            };

            return Json(dgMode);

        }

    }
}
